package cc.mrbird.febs.utils;

import cc.mrbird.febs.accounting.entity.DetailCost;

import java.math.BigDecimal;
import java.util.*;

public class CheckUtil {
    public static Boolean insuranceError(List<DetailCost> detailCosts) {
        Map<String, BigDecimal> projectInsurance = new HashMap<>();
        Map<String, BigDecimal> accrualInsurance = new HashMap<>();
        Set<String> yearMonths = new HashSet<>();
        for (DetailCost detailCost : detailCosts) {
            if (detailCost.getDetailSubjectCode().equals(CodeConstant.projectInsurance)) {
                projectInsurance.put(detailCost.getYearMonth(), detailCost.getCost());
                if (detailCost.getEstimate() == 0)
                    yearMonths.add(detailCost.getYearMonth());
            }
            if (detailCost.getDetailSubjectCode().equals(CodeConstant.accrualInsurance))
                accrualInsurance.put(detailCost.getYearMonth(), detailCost.getCost());
        }
        for (String yearMonth : yearMonths) {
            if (accrualInsurance.getOrDefault(yearMonth, BigDecimal.ZERO)
                    .compareTo(projectInsurance.getOrDefault(yearMonth, BigDecimal.ZERO)) > 0) {
                return true;
            }
        }
        return false;
    }
}
